﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Bangle.Common;
using Bangle.Model;
namespace Bangle.BLL {
	 	//T_Phone
		public partial class T_PhoneBLL
	{
   		     
		private readonly Bangle.DAL.T_PhoneDAL dal=new Bangle.DAL.T_PhoneDAL();
		public T_PhoneBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid PhoneId)
		{
			return dal.Exists(PhoneId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void  Add(Bangle.Model.T_Phone model)
		{
						dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Bangle.Model.T_Phone model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid PhoneId)
		{
			
			return dal.Delete(PhoneId);
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Bangle.Model.T_Phone GetModel(Guid PhoneId)
		{
			
			return dal.GetModel(PhoneId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Bangle.Model.T_Phone GetModelByCache(Guid PhoneId)
		{
			
			string CacheKey = "T_PhoneModel-" + PhoneId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(PhoneId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Bangle.Model.T_Phone)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Bangle.Model.T_Phone> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Bangle.Model.T_Phone> DataTableToList(DataTable dt)
		{
			List<Bangle.Model.T_Phone> modelList = new List<Bangle.Model.T_Phone>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Bangle.Model.T_Phone model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Bangle.Model.T_Phone();					
																									if(dt.Rows[n]["PhoneId"].ToString()!="")
				{
					model.PhoneId= Guid.Parse(dt.Rows[n]["PhoneId"].ToString());
				}
																								model.PhoneName= dt.Rows[n]["PhoneName"].ToString();
																																model.PhoneCode= dt.Rows[n]["PhoneCode"].ToString();
																																								if(dt.Rows[n]["SupplierId"].ToString()!="")
				{
					model.SupplierId= Guid.Parse(dt.Rows[n]["SupplierId"].ToString());
				}
																				if(dt.Rows[n]["RMB"].ToString()!="")
				{
					model.RMB=decimal.Parse(dt.Rows[n]["RMB"].ToString());
				}
																																				model.PartNo= dt.Rows[n]["PartNo"].ToString();
																																model.Specification= dt.Rows[n]["Specification"].ToString();
																												if(dt.Rows[n]["USD"].ToString()!="")
				{
					model.USD=decimal.Parse(dt.Rows[n]["USD"].ToString());
				}
																																if(dt.Rows[n]["PCS"].ToString()!="")
				{
					model.PCS=decimal.Parse(dt.Rows[n]["PCS"].ToString());
				}
																																if(dt.Rows[n]["CreateUserId"].ToString()!="")
				{
					model.CreateUserId=int.Parse(dt.Rows[n]["CreateUserId"].ToString());
				}
																																				model.CreateTime= dt.Rows[n]["CreateTime"].ToString();
																												if(dt.Rows[n]["UpdateUserId"].ToString()!="")
				{
					model.UpdateUserId=int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
				}
																																				model.UpdateTime= dt.Rows[n]["UpdateTime"].ToString();
																												if(dt.Rows[n]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(dt.Rows[n]["Valid"].ToString());
				}
																																if(dt.Rows[n]["ScreenId"].ToString()!="")
				{
					model.ScreenId=int.Parse(dt.Rows[n]["ScreenId"].ToString());
				}
																																if(dt.Rows[n]["ChipId"].ToString()!="")
				{
					model.ChipId=int.Parse(dt.Rows[n]["ChipId"].ToString());
				}
																																if(dt.Rows[n]["SeriesId"].ToString()!="")
				{
					model.SeriesId=int.Parse(dt.Rows[n]["SeriesId"].ToString());
				}
																																				model.SalePoint= dt.Rows[n]["SalePoint"].ToString();
																												if(dt.Rows[n]["SystemId"].ToString()!="")
				{
					model.SystemId=int.Parse(dt.Rows[n]["SystemId"].ToString());
				}
																																if(dt.Rows[n]["FrequencyId"].ToString()!="")
				{
					model.FrequencyId=int.Parse(dt.Rows[n]["FrequencyId"].ToString());
				}
																																if(dt.Rows[n]["NetWorkId"].ToString()!="")
				{
					model.NetWorkId=int.Parse(dt.Rows[n]["NetWorkId"].ToString());
				}
																																if(dt.Rows[n]["SimTypeId"].ToString()!="")
				{
					model.SimTypeId=int.Parse(dt.Rows[n]["SimTypeId"].ToString());
				}
																																if(dt.Rows[n]["ScreenPixelId"].ToString()!="")
				{
					model.ScreenPixelId=int.Parse(dt.Rows[n]["ScreenPixelId"].ToString());
				}
																																if(dt.Rows[n]["RAMId"].ToString()!="")
				{
					model.RAMId=int.Parse(dt.Rows[n]["RAMId"].ToString());
				}
																																if(dt.Rows[n]["ROMId"].ToString()!="")
				{
					model.ROMId=int.Parse(dt.Rows[n]["ROMId"].ToString());
				}
																																if(dt.Rows[n]["CameraFrontId"].ToString()!="")
				{
					model.CameraFrontId=int.Parse(dt.Rows[n]["CameraFrontId"].ToString());
				}
																																if(dt.Rows[n]["CameraBackId"].ToString()!="")
				{
					model.CameraBackId=int.Parse(dt.Rows[n]["CameraBackId"].ToString());
				}
																																if(dt.Rows[n]["BatteryTypeId"].ToString()!="")
				{
					model.BatteryTypeId=int.Parse(dt.Rows[n]["BatteryTypeId"].ToString());
				}
																																if(dt.Rows[n]["EarphoneId"].ToString()!="")
				{
					model.EarphoneId=int.Parse(dt.Rows[n]["EarphoneId"].ToString());
				}
																																if(dt.Rows[n]["ChargerId"].ToString()!="")
				{
					model.ChargerId=int.Parse(dt.Rows[n]["ChargerId"].ToString());
				}
																																				model.Color= dt.Rows[n]["Color"].ToString();
																																model.Accessories= dt.Rows[n]["Accessories"].ToString();
																																model.Size= dt.Rows[n]["Size"].ToString();
																						
				
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
#endregion
   
	}
}